using Sirenix.OdinInspector;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SpriteLocalizer : Localizer
{
    [Serializable]
    public class ConfigEntry
    {
        public string language;
        public Sprite sprite;
    }

    [ShowInInspector]
    public List<ConfigEntry> configList = new List<ConfigEntry>();

    ConfigEntry FindEntry(string language)
    {
        foreach(var entry in configList) 
        {
            if(entry.language == language)
            {
                return entry;
            }
        }
        return null;
    }

    Image _image;
    Image Image
    {
        get
        {
            if(_image == null)
            {
                this._image = this.GetComponent<Image>();
            }
            return _image;
        }
    }

    protected override void Refresh()
    {
        var entry = this.FindEntry(this.Language);
        if(entry == null)
        {
            return;
        }
        this.Image.sprite = entry.sprite;
    }
}

